package Extra01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Programa {

	static InputStreamReader sr;
	static BufferedReader br;
	
	public static void main(String[] args) {
		int opc;
		IFiguraInfo info;
		sr = new InputStreamReader(System.in);
		br = new BufferedReader(sr);		
		
		do{
		do{
		System.out.println("[ Menu de opciones ]");
		System.out.println("1-Crear un Circulo.");
		System.out.println("2-Crear un Rectangulo.");
		System.out.println("3-Crear un Triangulo.");
		System.out.println("4-Salir.");
		System.out.println();
		System.out.print("Opcion: ");
		opc = LectorInt();
		}while(opc < 1 && opc > 4);
		
		System.out.println();
		System.out.println();
		
		switch (opc)
		{
		case 1:
			System.out.println("Ingrese el radio del Circulo:");
			info = new Circulo(LectorDouble());
			break;
		case 2:
			info = opcRectangulo();
			break;
		case 3:
			info = opcTriangulo();
			break;
		default:
			info = null;			
			break;
		}
		if(opc >=1 && opc <= 3)
		{
			System.out.println(info.getInfo());
			System.out.println("Area: " + info.getArea());
			System.out.println("Perimetro: " + info.getPerimetro());
			System.out.println();
			System.out.println();
		}
		}while(opc != 4);
	}
	
	public static String Lector()
	{
		try
		{
			return br.readLine();
		}catch (IOException e)
		{
			return "";
		}
	}

	public static int LectorInt()
	{
		try
		{
			return Integer.parseInt(Lector());
		}
		catch (NumberFormatException e)
		{
			return 0;
		}
	}
	
	public static double LectorDouble()
	{
		try
		{
			return Double .parseDouble(Lector());
		}
		catch (NumberFormatException e)
		{
			return 1.0;
		}
	}

	public static IFiguraInfo opcRectangulo()
	{
		int opcR;
		double b,a;
		IFiguraInfo i;
		do{
		System.out.println("[ opcines de rectangulo ]");
		System.out.println("1-Rectangulo.");
		System.out.println("2-Cuadrado.");
		System.out.println();
		System.out.print("Opcion: ");
		opcR = LectorInt();
		
		switch (opcR) {
		case 1:
			System.out.println("Ingrese la base:");
			b = LectorDouble();
			System.out.println("Ingrese la altura:");
			a = LectorDouble();
			i = new Rectangulo(b, a);
			break;
		case 2:
			System.out.println("Ingrese el lado:");
			b = LectorDouble();			
			i = new Rectangulo(b);
			break;
		default:
			i = null;
			break;
		}
		}while(opcR < 1 && opcR > 2);
		return i;
	}

	public static IFiguraInfo opcTriangulo()
	{
		int opcR;
		double la,lb,lc;
		IFiguraInfo i;
		do{
		System.out.println("[ opcines de triangulo ]");
		System.out.println("1-Equilatero.");
		System.out.println("2-Isoceles.");
		System.out.println("3-Escaleno.");
		System.out.println();
		System.out.print("Opcion: ");
		opcR = LectorInt();
		
		switch (opcR) {
		case 1:
			System.out.println("Ingrese el lado:");
			la = LectorDouble();
			i = Triangulo.CrearTrianguloEquilatero(la);
			break;
		case 2:
			System.out.println("Ingrese el lado A:");
			la = LectorDouble();
			System.out.println("Ingrese el lado B:");
			lb = LectorDouble();
			i = Triangulo.CrearTrianguloIsoceles(la, lb);
			break;
		case 3:
			System.out.println("Ingrese el lado A:");
			la = LectorDouble();
			System.out.println("Ingrese el lado B:");
			lb = LectorDouble();
			System.out.println("Ingrese el lado C:");
			lc = LectorDouble();
			i = Triangulo .CrearTrianguloEscaleno(la, lb,lc );
			break;
		default:
			i = null;
			break;
		}
		}while(opcR < 1 && opcR > 3);
		return i;
	}
}
